<%@page import="java.text.DecimalFormat"%>
<%@page import="models.ProfitBySaler"%>
<%@page import="admin.data.GeoData"%>
<%@page import="models.GeoModel"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.util.Locale"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="java.util.List"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%	
	List<ProfitBySaler> list = (List<ProfitBySaler>)request.getAttribute("result");	
	NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
	NumberFormat nf1 = new DecimalFormat("0");
	String fromDate = "";
	String toDate = "";	
	String city = "";
	if(request.getAttribute("city")!=null&&!request.getAttribute("city").toString().isEmpty()){
		city = (String)request.getAttribute("city");		
	}	
	if(request.getAttribute("fromDate")!=null&&!request.getAttribute("fromDate").toString().isEmpty()){
		fromDate = (String)request.getAttribute("fromDate");		
	}
	if(request.getAttribute("toDate")!=null&&!request.getAttribute("toDate").toString().isEmpty()){
		toDate = (String)request.getAttribute("toDate");		
	}
	GeoData geoData = new GeoData();
	GeoModel currentCity;
	if(city!=null&&!city.isEmpty()){
		currentCity= geoData.getGeo(city);
	}else{
		currentCity = geoData.getFirstCity();
	}

%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>

<script type="text/javascript" src="/admin/js/sale_profit.js"></script>

<script type="text/javascript">
	jQuery(document).ready(function () {		
		jQuery("#fromDate, #toDate" ).datepicker();	
	});
	var server = "<%=UrlHelper.getServerUrl(request)%>";
</script>

        <div class="maincontent noright">
        	<div class="maincontentinner">
            	
                <ul class="maintabmenu">
                	<li><a href="/admin/sales/profit">Báo cáo doanh số</a></li>
                	<li><a href="/admin/sales/profit-detail">Báo cáo doanh số chi tiết</a></li>
                	<li class="current"><a href="/admin/sales/profit-by-saler">Báo cáo doanh số bán hàng theo nhân viên Sale</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">                
					<form class="stdform" action="/admin/sales/profit-by-saler" method="post">
                    	<div class="one_half">     
	                    	<p>
	                    		<label>Danh sách đơn hàng tại : </label>
	                            <span class="field">
		                            <select name="city" id="city">
		                            	<%
		                            		for(GeoModel geo: geoData.getCities()){
		                            	%>
		                            	<option <%=(city!=null&&city.equals(geo.getGeoId()))?"selected":"" %> value="<%=geo.getGeoId()%>"><%=geo.getName() %></option>	                                
		                                <%
		                            		}
		                                %>	                            
		                            </select>
	                            </span>                        
	                    	</p>                     	
	                        <p>
	                    		<label>Từ ngày : </label>
	                             <span class="field"><input type="text" name="fromDate" class="longinput" id="fromDate" value="<%=(fromDate!=null&&!fromDate.isEmpty())?fromDate:""%>"/></span>                            
	                    	</p>   
	                    	<p>
	                    		<label>Đến ngày : </label>
	                             <span class="field"><input type="text" name="toDate" class="longinput" id="toDate" value="<%=(toDate!=null&&!toDate.isEmpty())?toDate:""%>"/></span>                            
	                    	</p>                      	
	                    	<p class="stdformbutton">
	                        	<input type="submit" class="reset radius2" value="Tìm kiếm">
	                            <input type="reset" class="reset radius2" value="Làm lại">
	                        </p>                 	     	                    	        	                                         	
                    	</div><!--one_half-->                                                        	                    	       	                        					
                   </form> 
                   <br clear="all" /><br />                	
                	<div class="contenttitle radiusbottom0">
	                	<h2 class="table"><span>Kết quả tìm kiếm</span></h2>
	                </div>	                	           
	                <table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">	                   
	                    <thead>
	                        <tr>	                        	
	                            <th class="head1">STT</th>
	                            <th class="head0">Saler</th>
	                            <th class="head1">Display GP</th>
	                            <th class="head0">Real GP</th>
	                            <th class="head1">Rate(%)</th>	                            
	                        </tr>
	                    </thead>	                   
	                    <tbody>	
	                    <%
	                    	if(list!=null&&list.size()>0){
	                    		for(int i = 0; i< list.size();i++){
	                    %>                    	
	                        <tr>	                        	
								<td class="center"><%=i+1%></td>
	                            <td class="center"><%=list.get(i).getSalername()%></td>
	                            <td class="center"><%=nf.format(list.get(i).getDisplayGP())%></td>
	                            <td class="center"><%=nf.format(list.get(i).getRealGP())%></td>	                            
	                            <td class="center"><%=nf1.format(list.get(i).getRate()*100)%></td>	                                           
	                        </tr>	 
                        <%
	                    		}
                    		}
                        %>                     
	                    </tbody>
	                </table>	
	                <div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate">
	                	<% String url = URLEncoder.encode((String) UrlHelper.getServerUrl(request) + "/sales-profit-by-saler-file?fromDate=" + fromDate + "&toDate=" + toDate + "&action=toFile"); %>
	                 	<a class="paginate_button" target="blank" href="/export-excel?url=<%=url%>">Xuất File Excel</a>	                	
	                </div>                  	                	             
                </div><!--content-->                
            </div><!--maincontentinner-->            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>            
        </div><!--maincontent-->        
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>